package nju.mscs.gui;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;

import java.awt.IllegalComponentStateException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import nju.mscs.businesslogic.DS;
import nju.mscs.businesslogic.DataSynchronism;
import nju.mscs.server.businessLogic.Controller;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Entrance_m extends javax.swing.JFrame {

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}

	private JButton jButton1;
	private JPanel imagePanel;
	private JButton jButton2;
	private JLabel jLabel2;
	private JComboBox jComboBox1;
	private JLabel jLabel1;
	private JTextField jTextField1;
	static public ImageIcon background;
	private JLabel label;
    private Graphics g; 
    static private Controller  ctr = null;
    static private int key=0;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				if(Entrance_m.ctr==null){
					ctr=new Controller();
				}
				Entrance_m inst = new Entrance_m();
				inst.setLocationRelativeTo(null);			
				inst.setVisible(true);		
			}
		});
	}
	
	public Entrance_m() {
		super();
		if(key==0){
			ctr.start();
			key=1;
		}
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			this.setUndecorated(true);
			
			{
				jButton1 = new JButton();
				getContentPane().add(jButton1);
				jButton1.setText("\u9000\u51fa");
				jButton1.setBounds(751, 505, 200, 92);
				jButton1.setFont(new java.awt.Font("微软雅黑",0,36));
				jButton1.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButton1ActionPerformed(evt);
					}
				});
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("\u6b22\u8fce\u4f7f\u7528\u8d85\u5e02\u7ba1\u7406\u7cfb\u7edf\u603b\u5e97\u5ba2\u6237\u7aef");
				jLabel1.setBounds(341, 69, 781, 97);
				jLabel1.setFont(new java.awt.Font("微软雅黑",0,48));
			}
			{
				jButton2 = new JButton();
				getContentPane().add(jButton2);
				jButton2.setText("\u767b\u5f55");
				jButton2.setBounds(363, 505, 218, 92);
				jButton2.setFont(new java.awt.Font("微软雅黑",0,36));
				jButton2.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jButton2ActionPerformed(evt);
					}
				});
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("\u8bf7\u9009\u62e9\u60a8\u7684\u8eab\u4efd\u8fdb\u884c\u767b\u5f55");
				jLabel2.setBounds(487, 199, 437, 60);
				jLabel2.setFont(new java.awt.Font("微软雅黑",0,36));
			}
			{
				ComboBoxModel jComboBox1Model = 
					new DefaultComboBoxModel(
							new String[] { "总店经理","系统管理员" });
				jComboBox1 = new JComboBox();
				getContentPane().add(jComboBox1);
				jComboBox1.setModel(jComboBox1Model);
				jComboBox1.setBounds(564, 315, 277, 82);
				jComboBox1.setFont(new java.awt.Font("微软雅黑",0,28));
			}

			pack();
			this.setSize(1278, 689);
			getGraphicsConfiguration().getDevice().setFullScreenWindow(this);
			
			
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	
	private void jButton1ActionPerformed(ActionEvent evt) {
		//System.out.println("jButton1.actionPerformed, event="+evt);
		Boolean result= ctr.close();
		if(result){
		System.exit(1);}
		else{
			JOptionPane.showMessageDialog(this,"信息存储失败！ ");
			return;
		}
	}
	
	private void jButton2ActionPerformed(ActionEvent evt) {
		//System.out.println("jButton2.actionPerformed, event="+evt);
		String job = jComboBox1.getSelectedItem().toString();
		if(job.equals("总店经理")){
			login3.main(null);
			this.dispose();
		}
		if(job.equals("系统管理员")){
			login4_m.main(null);
			login4_m.setKey("1");
			this.dispose();
		}
	
	}

}
